package com.briup.mt.web.controller;

import com.briup.mt.bean.Category;
import com.briup.mt.service.ICategoryService;
import com.briup.mt.utils.Message;
import com.briup.mt.utils.MessageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
@Validated
public class CategoryController {
@Autowired
private ICategoryService categoryService;
@GetMapping("findAll")
public Message findAll(){
    List<Category>list=categoryService.findAll();
return MessageUtil.success(list);
}
@GetMapping("query")
public Message query(String name){
   List<Category>list=categoryService.query(name);
   return  MessageUtil.success(list);
}
@DeleteMapping("deleteById")
public Message deleteById(long id){
categoryService.deleteById(id);
return MessageUtil.success("删除成功");
}
@PostMapping("saveOrUpdate")
    public  Message saveOrUpdate(Category category){
categoryService.saveOrUpdate(category);
return MessageUtil.success("操作成功");
}
}

